Skip to content

providers: sqlate/postgres/pgtest, the one scratch-database helper - #25

Merged
JaimeStill merged 5 commits into
mainfrom
providers
Nov 17, 2026
Merged

JaimeStill merged 5 commits into
mainfrom
providers

Conversation

@JaimeStill

Copy link
Copy Markdown
Contributor

v1.ai.processing · task 8/11 · providers

Summary

sqlate/postgres/pgtest (new) one throwaway database per test
├ go-messaging/postgres onto pgtest; its own pgtest removed (Breaking)
└ blobfs/postgres onto pgtest; dbtest keeps only blobfs's helpers
docproc
├ go.work base · storage · postgres
├ storage/ (new module) dispatch.Content over go-storage
├ postgres/ (new module) dispatch.Index over sqlate on pgx
└ compose: PostgreSQL 18.7 :5436 · SeaweedFS 4.54 :8334
mise run integration → integration:postgres + integration:storage

Core changes

  1. pgtest — the one scratch-database helper
    type Database struct { Pool *sql.DB; DSN string }
    func Create(t testing.TB, env, prefix string) *Database
    func Migrated(t testing.TB, env, prefix string, sets ...migrate.Set) *Database
    func (d *Database) Session() *sqlate.DB
    why: round 2 — the third copy would have been docproc's; all users move first
  2. storage.New(Config{Client, Prefix, Renew}) (*Content, error)
    key ab/ab12… (stable; slashes on every platform); no sweeper
    why: rounds 1–2 — FileContent's layout; the host's lifecycle rule sweeps
  3. postgres.New(ctx, Config{DB *sqlate.DB, Lease, Flush}) (*Index, error)
    claim/renew/flush/record/release: conditional on the token, database clock
    entry and log items as jsonb with dispatch.Version; Append buffers Flush items
    Wait: LISTEN docproc_index on one held conn (Close), NOTIFY from
    Release/Record/Drop, a timer at a dead claimant's lease expiry
    why: rounds 1–2 — Wait on LISTEN since pgx is already in the graph
  4. postgres.NewRetention(db, age); Pass(ctx, budget) (more bool, err error)
    oldest first, never a live claim; age runs from the entry's first claim
    why: round 1 Q8 — Index has no listing, so the host can't sweep with Drop
  5. Migrations() "docproc" set (docproc_schema_version), golden hashes, Verify, Statements

Evidence

mise run check (sqlate, go-messaging, blobfs, docproc) ✓ all exit 0, lint 0 issues, sqlint ok
docproc mise run integration ✓ postgres 28 tests (dispatchtest Index
suite whole, Wait ×6, Retention ×3),
storage 9 (Content suite on s3/SeaweedFS)
docproc mise run test:integration ✓ tools tier over this checkout's builds,
then integration (slice 14)
sqlate mise run db:up && mise run integration && mise run db:down
✓ pgtest drop with a session open
go-messaging mise run integration ✓ postgres, nats, natstest
blobfs mise run acceptance ✓ postgres tier through pgtest
mise run currency (all four) ✓ only docproc's three recorded holds
spec review ✓ behaviors 1–15, no gaps

Decided without you

  1. Entry age: my slice 11 brief told Record to reset created_at, against the layers
    decision (age from first claim; neither Record nor a takeover refreshes it). The
    slice 14 implementer caught it; fixed in 20f09b5 and the tests pin it.
  2. NewRetention(db, age) is positional, as layers.md states and NewFileContent/
    NewMemoryIndex do, rather than a Config struct (standards-reviewer raised it).
  3. postgres.New takes a ctx: it checks the pgx driver through Conn.Raw, since
    sqlate.DB doesn't expose its pool. Index.Close releases the lazy LISTEN conn.
  4. A takeover is the conditional claim plus discard_items in one transaction.
  5. Harness: ports 5436/8334 under DOCPROC_* names; crane pinned for image-pin
    currency; CI's integration job has its own paths filter and workflow_dispatch.
  6. Standards review: a test proving Wait wakes on NOTIFY (a polling Wait now
    fails, checked by mutation); a listener-restart test no longer passes on the
    dying backend; version refusal and UTC TestMain tightened; sqlate's pgtest
    documented in README and docs/, a pool leak fixed.
  7. Slice 11 was stopped mid-work at your pause and finished by a fresh implementer.

Merge danger

one-way door: the tags sqlate postgres/v0.8.0, go-messaging postgres/v0.4.0,
docproc storage/v0.1.0 and postgres/v0.1.0, and go-messaging's pgtest removal
once released
SHIP order: sqlate merges and tags postgres/v0.8.0 first; then docproc,
go-messaging, and blobfs each swap the temporary replace for v0.8.0 (blobfs
bumps its require from v0.7.0), pass CI, and merge; then tag storage/v0.1.0,
postgres/v0.1.0, and go-messaging's postgres/v0.4.0
blast radius: go-web-service will see go-messaging/postgres v0.4.0 trailing
(no pgtest use, nothing to adapt); a plan-v1.ai.processing PR then drops
sqlate, go-messaging, and blobfs from the goal's repos

Needs you

(none)

- workflows: jdx/mise-action v5.2.7 -> v5.2.9 (ci.yml; release.yml does
  not use it)
- compose/postgres/Dockerfile: postgres 18.6-alpine -> 18.7-alpine
- docs/quick-start.md: the quoted Dockerfile follows its FROM line

Both are bug and security fixes with nothing to adapt. Pin bumps are not
recorded in the changelog, matching past upgrades. The integration tier
passes against 18.7 on the existing development volume.
pgtest folds go-messaging's pgtest and blobfs's internal dbtest into one
public package of the postgres module: Create makes <prefix>_test_<hex>
on the server whose admin DSN the named variable holds (failing the test
when it is unset), Migrated applies migrate sets under the PostgreSQL
dialect, and Database.Session wraps the pool under postgres.Dialect. At
cleanup the pool closes and the database drops WITH (FORCE), retrying
while the server reports a closing session; a timed-out CREATE is
dropped IF EXISTS on its own context.

The database name is quoted with pgx.Identifier, so it reaches the server
exactly as the returned DSN spells it, and failure messages name the
database rather than the DSN, which carries the password. The live proof
holds a second pool's session open across the drop and checks from the
admin connection that the database is gone.
- [v0.8.0] - 2026-11-17 heads the pgtest Added entries; [Unreleased] is
  empty above it, and the compare links gain v0.8.0's
  (postgres/v0.7.0...postgres/v0.8.0) with [Unreleased] from
  postgres/v0.8.0.
- No Requires line: the sqlate requirement is unchanged from v0.7.0.
…s.md, as STANDARDS.md requires of a documented change
… sleeps only between drop attempts; its live test fails rather than panics without a held session
@JaimeStill
JaimeStill merged commit 2798c01 into main Nov 17, 2026
1 check passed
@JaimeStill
JaimeStill deleted the providers branch November 17, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant